package roborally;

public class Facade implements IFacade {

	@Override
	public IRobot createRobot(long x, long y, int orientation, double energy) {
		try{
			if ( (energy >= 0) && (energy <= 20000) )
				return new Robot (x, y, orientation, energy);
			else return null;
		}
		catch(IllegalArgumentException exc) {
			return null;
		}
	}

	@Override
	public long getX(IRobot robot) {
		return robot.getX();
	}

	@Override
	public long getY(IRobot robot) {
		return robot.getY();
	}

	@Override
	public int getOrientation(IRobot robot) {
		return robot.getOrientation();
	}

	@Override
	public void move(IRobot robot) {
		if (robot.getEnergy() >= 500)
			robot.move();
	}

	@Override
	public void turnClockwise(IRobot robot) {
		if (robot.getEnergy() >= 100)
			robot.turnClockwise();
	}

	@Override
	public double getEnergy(IRobot robot) {
		return robot.getEnergy();
	}

	@Override
	public void recharge(IRobot robot, double energyAmount) {
		if ((energyAmount > 0) && ( ( (Robot) robot).getMaxEnergy() >= robot.getEnergy() + energyAmount) )
			robot.recharge(energyAmount);
	}

	@Override
	public int isGetEnergyRequiredToReachAndMoveNextTo16Plus() {
		// means that we implement the energy required for the turns in 
		// getEnergyRequiredToReach and moveNextTo
		return 1;
	}

	@Override
	public double getEnergyRequiredToReach(IRobot robot, long x, long y) {
		return robot.getEnergyRequiredToReach(x, y);
	}

	@Override
	public void moveNextTo(IRobot robot, IRobot robot2) {
		robot.moveNextTo(robot2);
	}

}
